package com.sia.springcloud.protocol.model;

import com.sia.springcloud.model.Device;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @Author: Sirius
 * @Date: 2021/10/3 20:16
 * @Description: 111
 **/
@Slf4j
@Data
public class BoschDevice implements Serializable {
    private Integer id;
    private Integer collect;
    private String microservice;
    private String protocolName;
    private String deviceName;
    private String description;
//    数据库地址
    private String host;
//    数据库端口
    private Integer port;
    private Integer timeout;
    private Integer connectionLimit;
//    数据库用户名
    private String username;
//    数据库密码
    private String password;
    //    数据库名
    private String dbName;
//    文件路径
    private String filePath;

//    用于存放数据库列名，这个是固定的，
    private String titles="protRecord_ID\tdateTime\ttimerName\tprogNo\tspotName\twear\twearPerCent\tmonitorState\tmonitorState_txt\tregulationState\tregulationState_txt\tmeasureState\tmeasureState_txt\tpowerState\tpowerState_txt\tsequenceState\tsequenceState_txt\tsequenceStateAdd\tsequenceStateAdd_txt\tsequenceRepeat\tsequenceRepeat_txt\tmonitorMode\tmonitorMode_txt\tiDemandStd\tilsts\tregulationStd\tregulationStd_txt\tiDemand1\tiActual1\tregulation1\tregulation1_txt\tiDemand2\tiActual2\tregulation2\tregulation2_txt\tiDemand3\tiActual3\tregulation3\tregulation3_txt\tphaStd\tpha1\tpha2\tpha3\tt_iDemandStd\ttActualStd\tpartIdentString\ttipDressCounter\telectrodeNo\tvoltageActualValue\tvoltageRefValue\tcurrentActualValue\tcurrentReferenceValue\tweldTimeActualValue\tweldTimeRefValue\tenergyActualValue\tenergyRefValue\tpowerActualValue\tpowerRefValue\tresistanceActualValue\tresistanceRefValue\tpulseWidthActualValue\tpulseWidthRefValue\tstabilisationFactorActValue\tstabilisationFactorRefValue\tthresholdStabilisationFactor\twldEffectStabilisationFactor\tuipActualValue\tuipRefValue\tuirExpulsionTime\tuirMeasuringActive\tuirMeasuringActive_txt\tuirRegulationActive\tuirRegulationActive_txt\tuirMonitoringActive\tuirMonitoringActive_txt\tuirWeldTimeProlongationActive\tuirWeldTimeProlongationActive_txt\tuirQStoppRefCntValue\tuirQStoppActCntValue\tuirUipUpperTol\tuirUipLowerTol\tuirUipCondTol\tuirPsfLowerTol\tuirPsfCondTol";



    private static final long serialVersionUID = 1L;

    /**
     * 将Modbus设备对象转换成Protocol设备对象
     *
     * @param boschDevice
     * @return
     */
    public static Device convert(BoschDevice boschDevice) {
        Device device = new Device();
        device.setId(boschDevice.getId());
        device.setCollect(boschDevice.getCollect());
        device.setMicroservice(boschDevice.getMicroservice());
        device.setProtocolName(boschDevice.getProtocolName());
        device.setDeviceName(boschDevice.getDeviceName());
        device.setDescription(boschDevice.getDescription());
        device.setHost(boschDevice.getHost());
        device.setPort(boschDevice.getPort());
        device.setTimeout(boschDevice.getTimeout());
        device.setConnectionLimit(boschDevice.getConnectionLimit());
        device.setUsername(boschDevice.getUsername());
        device.setPassword(boschDevice.getPassword());
//        用Str1存数据库名
        device.setVarStr1(boschDevice.getDbName());
//        用str2存放文件路径
        device.setVarStr2(boschDevice.getFilePath());


        return device;
    }

    /**
     * 将Protocol设备对象转换成Modbus设备对象
     *
     * @param device
     * @return
     */
    public static BoschDevice reconvert(Device device) {

        BoschDevice boschDevice = new BoschDevice();

        boschDevice.setId(device.getId());
        boschDevice.setCollect(device.getCollect());
        boschDevice.setMicroservice(device.getMicroservice());
        boschDevice.setProtocolName(device.getProtocolName());
        boschDevice.setDeviceName(device.getDeviceName());
        boschDevice.setDescription(device.getDescription());
        boschDevice.setHost(device.getHost());
        boschDevice.setPort(device.getPort());
        boschDevice.setTimeout(device.getTimeout());
        boschDevice.setConnectionLimit(device.getConnectionLimit());
        boschDevice.setUsername(device.getUsername());
        boschDevice.setPassword(device.getPassword());
//        用Str1存数据库名
        boschDevice.setDbName(device.getVarStr1());
//        用str2存放文件路径
        boschDevice.setFilePath(device.getVarStr2());

        return boschDevice;
    }
}
